//
//  BZGUISegmentedControlController.m
//  BZGCode
//
//  Created by coderz on 2019/12/31.
//  Copyright © 2019 coderz. All rights reserved.
//

#import "BZGUISegmentedControlController.h"

@interface BZGUISegmentedControlController ()

@property (nonatomic, strong) UISegmentedControl *segControl;

@end

@implementation BZGUISegmentedControlController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.segControl];
    self.segControl.frame = CGRectMake(100, 100, 200, 40);
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
}

-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
}

- (void)selectItem:(UISegmentedControl *)control {
    NSLog(@"1");
}

-(UISegmentedControl *)segControl {
    if (_segControl == nil) {
        _segControl = [[UISegmentedControl alloc] initWithItems:@[@"委托查询",@"成交查询"]];
        _segControl.selectedSegmentIndex = 0;
                _segControl.tintColor = [UIColor redColor];
                
                [_segControl setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];
                [_segControl setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName] forState:UIControlStateSelected];
                [_segControl setBackgroundImage:[UIImage imageWithColor:[UIColor redColor]] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
                [_segControl setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
                

                 [_segControl addTarget:self action:@selector(selectItem:) forControlEvents:UIControlEventValueChanged];
                
                
                _segControl.layer.borderColor = [UIColor redColor].CGColor;
                _segControl.layer.borderWidth = 1;
                _segControl.backgroundColor = [UIColor clearColor];
        //        _segControl.layer.cornerRadius = 20;
                _segControl.layer.masksToBounds = YES;
    }
    return _segControl;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
